package net.moonbiter.ebs.callers;

import java.io.IOException;
import java.util.Map;

import net.moonbiter.OperationFailureException;
import net.moonbiter.ebs.ServiceCaller;
import net.moonbiter.ebs.validation.ValidationException;

public class ComponibleServiceCaller<INPUT,OUTPUT> extends ServiceCaller<INPUT,OUTPUT> {	
	private InputInterpreter<INPUT> interpreter;
	private OutputDeliverer<OUTPUT> deliverer;
	
	public ComponibleServiceCaller(
			InputInterpreter<INPUT> interpreter, OutputDeliverer<OUTPUT> deliverer){
		this.interpreter = interpreter;
		this.deliverer = deliverer;
	}

	@Override
	public void deliverError(OUTPUT output, Exception exception) throws IOException {
		deliverer.deliverError(output, exception);		
	}

	@Override
	protected void deliverResult(OUTPUT output, Object result) throws IOException {
		deliverer.deliverResult(output, result);
	}

	@Override
	public Map<String,Object> obtainParams(INPUT inputs, Map<String, Class<?>> requiredLogicalParams)
			throws ValidationException, OperationFailureException {
		return interpreter.obtainParams(inputs, requiredLogicalParams);
	}

}
